/** 获取牌组牌型
 */
var _ = require('./../../FrameWork/we_underscore');
var EumPkGroup = require('./../Enum/EumPkGroup');
var FindBomb = require('./FindBomb');
var FindThree = require('./FindThree');
var FindFour = require('./FindFour');
var FindPairsTool = require('./FindPairsTool');

var FindShunZiTool = require('./FindShunZiTool');

var FindCardGroupType = module.exports = {};

/**获取牌组牌型 
 */
FindCardGroupType.getType = function(_cardInfos) {
    var size = _.size(_cardInfos);
    // var _canTypes = [];
    if (1 == size) {
        return EumPkGroup.ONE;
    }
    /***可能王炸 ，一对 */
    else if (2 == size) {
        // _canTypes = [EumPkGroup.BOMBKING, EumPkGroup.PAIRS];
        if (true == FindPairsTool.isOnePairs(_cardInfos)) {
            return EumPkGroup.PAIRS;
        }
        if (true == FindBomb.isBombKing(_cardInfos)) {
            return EumPkGroup.BOMBKING;
        }
    }
    /***三张 */
    else if (3 == size) {
        if (true == FindThree.isFind(_cardInfos)) {
            return EumPkGroup.THREE;
        }
    }
    /***炸弹,三带一*/
    else if (4 == size) {
        // _canTypes = [EumPkGroup.BOMB, EumPkGroup.THREEONE];
        if (true == FindBomb.isBomb(_cardInfos)) {
            return EumPkGroup.BOMB;
        }
        if (true == FindThree.isBeltOne(_cardInfos)) {
            return EumPkGroup.THREEONE;
        }
    }
    /***三带对子,三带二,四带一*/
    else if (5 == size) {
        if (true == FindThree.isBeltPairs(_cardInfos)) {
            return EumPkGroup.THREEPAIRS;
        }
        if (true == FindThree.isBeltTwo(_cardInfos)) {
            return EumPkGroup.THREETWO;
        }
        if (true == FindFour.isBeltOne(_cardInfos)) {
            return EumPkGroup.FOURONE;
        }
    }
    /***四带二,连对,飞机*/
    else if (6 == size) {
        if (true == FindFour.isBeltTwo(_cardInfos)) {
            return EumPkGroup.FOURTWO;
        }
        if (true == FindPairsTool.isEvenPair(_cardInfos)) {
            return EumPkGroup.EVENPAIRS;
        }
        if (true == FindThree.isAircraft(_cardInfos)) {
            return EumPkGroup.AIRCRAFT;
        }
        // _canTypes = [EumPkGroup.STRAIGHT, EumPkGroup.FOURTWO, EumPkGroup.EVENPAIRS, EumPkGroup.AIRCRAFT];
    }
    /***四带三*/
    else if (7 == size) {
        if (true == FindFour.isBeltThree(_cardInfos)) {
            return EumPkGroup.FOURTHREE;
        }
        // _canTypes = [EumPkGroup.STRAIGHT, EumPkGroup.FOURTHREE];
    }
    /***四带二对 */
    else if (8 == size) {
        if (true == FindFour.isBeltTwoPairs(_cardInfos)) {
            return EumPkGroup.FOURTWOPAIRS;
        }
        if (true == FindThree.isAircraft(_cardInfos)) {
            return EumPkGroup.AIRCRAFT;
        }
        // _canTypes = [EumPkGroup.STRAIGHT, EumPkGroup.FOURTWOPAIRS];
    } else {
        if (true == FindThree.isAircraft(_cardInfos)) {
            return EumPkGroup.AIRCRAFT;
        }
    }

    /***顺子*/
    if (FindShunZiTool.isShunZi(_cardInfos)) {
        return EumPkGroup.STRAIGHT;
    }
    /***连对*/
    if (true == FindPairsTool.isEvenPair(_cardInfos)) {
        return EumPkGroup.EVENPAIRS;
    }
    /***飞机*/
    if (true == FindThree.isAircraft(_cardInfos)) {
        return EumPkGroup.AIRCRAFT;
    }
    cc.error('牌型异常');
    return EumPkGroup.NONE;
};